//
//  HNFamilyMobilizeController.m
//  XDEducation
//
//  Created by 星道 on 17/5/24.
//  Copyright © 2017年 apple. All rights reserved.
//

#import "HNFamilyMobilizeController.h"
#import "HNFamilyMobilizeCell.h"
#import "HNFamilyMobilizeModel.h"
#import "WebViewController.h"

@interface HNFamilyMobilizeController ()<UICollectionViewDelegate,UICollectionViewDataSource>
@property (nonatomic, strong) NSArray *DataArr;
@property (nonatomic, strong) UICollectionView *collectionView;
@end

@implementation HNFamilyMobilizeController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.view.backgroundColor = UIColor(240, 240, 240);
    
    [self.view addSubview:self.collectionView];

    
    [self.collectionView registerNib:[UINib nibWithNibName:[HNFamilyMobilizeCell description] bundle:nil] forCellWithReuseIdentifier:@"Cell"];


}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}



#pragma mark <UICollectionViewDataSource>

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.DataArr.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    HNFamilyMobilizeCell *Cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
    HNFamilyMobilizeModel *Model = self.DataArr[indexPath.item];
    Cell.Model = Model;
    return Cell;
}


- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    HNFamilyMobilizeModel *Model = self.DataArr[indexPath.row];
    WebViewController *VC = [[WebViewController alloc] init];
    VC.str = BaseURL([self NetWorkUrlWithIndex:indexPath.item]);
    VC.nameTitle = Model.Title;
    [self.navigationController pushViewController:VC animated:YES];
}


#pragma mark Function
/** 获取网络请求参数 */
- (NSString *)NetWorkUrlWithIndex:(NSInteger)Index
{
    if (Index == 0)
    {
        return @"bbsws.do?action=showalltopic&pageNumber=1&forumcode=XXDD_XXSQ_QJZDY_QJLHD_ZJHDCY";
    }
    else if (Index == 1)
    {
        return @"bbsws.do?action=familytoEvents&pageNumber=1&forumcode=XXDD_XXSQ_QJZDY_QJLHD_HDBK";
    }
    else if (Index == 2)
    {
        return @"bbsws.do?action=showalltopic&pageNumber=1&forumcode=XXDD_XXSQ_QJZDY_QJLHD_QJLX";
    }
    else if (Index == 3)
    {
        return @"bbsws.do?action=showalltopic&pageNumber=1&forumcode=XXDD_XXSQ_QJZDY_QJLLC_ZJLCGZ";
    }
    else if (Index == 4)
    {
        return @"bbsws.do?action=familytoEvents&pageNumber=1&forumcode=XXDD_XXSQ_QJZDY_QJLLC_LCBK";
    }
    else
    {
        return @"bbsws.do?action=showalltopic&pageNumber=1&forumcode=XXDD_XXSQ_QJZDY_QJLLC_LCJYX";
    }
}



#pragma mark - Setter
- (NSArray *)DataArr
{
    if (!_DataArr)
    {
        _DataArr = [HNFamilyMobilizeModel GetFamilyMobilizeModelForArr];
    }
    return _DataArr;
}

- (UICollectionView *)collectionView
{
    if (!_collectionView)
    {
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 10, ScreenW, ScreenH-10) collectionViewLayout:[self collectionViewFlowLayout]];
        _collectionView.backgroundColor = [UIColor whiteColor];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
    }
    return _collectionView;
}
- (UICollectionViewFlowLayout *)collectionViewFlowLayout
{
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    layout.itemSize = CGSizeMake(ScreenW/3.5, (ScreenW/3)*1.2);
    layout.scrollDirection = UICollectionViewScrollDirectionVertical;
    return layout;
}

@end
